package com.ruoyi.project.channel.businessCaptialSetting.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.businessCaptialSetting.domain.BusinessCaptialSetting;
import com.ruoyi.project.channel.businessCaptialSetting.service.IBusinessCaptialSettingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * business_capital_setting信息操作处理
 * 
 * @author CAIN
 * @date 2019-09-29
 */
@Controller
@RequestMapping("/channel/businessCaptialSetting")
public class BusinessCaptialSettingController extends BaseController
{
    private String prefix = "channel/businessCaptialSetting";
	
	@Autowired
	private IBusinessCaptialSettingService businessCaptialSettingService;
	
	@RequiresPermissions("channel:businessCaptialSetting:view")
	@GetMapping()
	public String businessCaptialSetting()
	{
	    return prefix + "/businessCaptialSetting";
	}
	
	/**
	 * 查询business_capital_setting列表
	 */
	@RequiresPermissions("channel:businessCaptialSetting:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(BusinessCaptialSetting businessCaptialSetting)
	{
		startPage();
        List<BusinessCaptialSetting> list = businessCaptialSettingService.selectBusinessCaptialSettingList(businessCaptialSetting);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出business_capital_setting列表
	 */
	@RequiresPermissions("channel:businessCaptialSetting:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusinessCaptialSetting businessCaptialSetting)
    {
    	List<BusinessCaptialSetting> list = businessCaptialSettingService.selectBusinessCaptialSettingList(businessCaptialSetting);
        ExcelUtil<BusinessCaptialSetting> util = new ExcelUtil<BusinessCaptialSetting>(BusinessCaptialSetting.class);
        return util.exportExcel(list, "businessCaptialSetting");
    }
	
	/**
	 * 新增business_capital_setting
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存business_capital_setting
	 */
	@RequiresPermissions("channel:businessCaptialSetting:add")
	@Log(title = "business_capital_setting", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(BusinessCaptialSetting businessCaptialSetting)
	{		
		return toAjax(businessCaptialSettingService.insertBusinessCaptialSetting(businessCaptialSetting));
	}

	/**
	 * 修改business_capital_setting
	 */
	@GetMapping("/edit/{businessId}")
	public String edit(@PathVariable("businessId") Long businessId, ModelMap mmap)
	{
		BusinessCaptialSetting businessCaptialSetting = businessCaptialSettingService.selectBusinessCaptialSettingByBusiness(businessId);
		if(businessCaptialSetting == null){
			businessCaptialSetting = businessCaptialSettingService.selectBusinessCaptialSettingByBusiness(1L);
			businessCaptialSetting.setCapitalId(null);
			businessCaptialSetting.setBusinessId(businessId);
//			businessCaptialSettingService.insertBusinessCaptialSetting(businessCaptialSetting);
		}
		mmap.put("businessCaptialSetting", businessCaptialSetting);
	    return prefix + "/edit";
	}

	/**
	 * 修改business_capital_setting
	 */
	@GetMapping("/editSystem")
	public String edit(ModelMap mmap)
	{
		BusinessCaptialSetting businessCaptialSetting = businessCaptialSettingService.selectBusinessCaptialSettingByBusiness(1L);
		mmap.put("businessCaptialSetting", businessCaptialSetting);
		return prefix + "/editSystem";
	}

	/**
	 * 修改business_capital_setting
	 */
	@GetMapping("/getSystem")
	@ResponseBody
	public AjaxResult getSystem()
	{
		BusinessCaptialSetting businessCaptialSetting = businessCaptialSettingService.selectBusinessCaptialSettingByBusiness(1L);
		return AjaxResult.success("success", businessCaptialSetting);
	}

	/**
	 * 修改保存business_capital_setting
	 */
	@RequiresPermissions("channel:businessCaptialSetting:edit")
	@Log(title = "business_capital_setting", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(BusinessCaptialSetting businessCaptialSetting)
	{
		BusinessCaptialSetting businessCaptialSetting1 = businessCaptialSettingService.selectBusinessCaptialSettingByBusiness(businessCaptialSetting.getBusinessId());
		if(businessCaptialSetting1 == null){
			return toAjax(businessCaptialSettingService.insertBusinessCaptialSetting(businessCaptialSetting));
		}
		return toAjax(businessCaptialSettingService.updateBusinessCaptialSetting(businessCaptialSetting));
	}
	
	/**
	 * 删除business_capital_setting
	 */
	@RequiresPermissions("channel:businessCaptialSetting:remove")
	@Log(title = "business_capital_setting", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(businessCaptialSettingService.deleteBusinessCaptialSettingByIds(ids));
	}
	
}
